	package sharing.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Persistence;
import javax.persistence.TypedQuery;

@Entity
@IdClass(sharing.model.SharingPK.class)
public class Sharing {

	

	@Id
	private long idSharing;

	@Id
    private String idClient;
	
	@ManyToOne
	private Client clientSender;
	

	// liste des personnes qui recoive le partage
	@ManyToMany(targetEntity = sharing.model.Client.class, mappedBy = "shared")
	private List<Client> sharingReceivers = new ArrayList<>();

	private long date;

	private String type;
	
	private String path;
	
	private String name;
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Client getClientSender() {
		return clientSender;
	}

	public void setClientSender(Client clientSender) {
		this.clientSender = clientSender;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public Sharing() {
	}

	public long getDate() {
		return date;
	}

	public void setDate(long date) {
		this.date = date;
	}

	public long getIdSharing() {
		return idSharing;
	}

	public void setIdSharing(long idSharing) {
		this.idSharing = idSharing;
	}

	public String getIdClient() {
		return idClient;
	}

	public void setIdClient(String idClient) {
		this.idClient = idClient;
	}

	public List<Client> getSharingReceivers() {
		if (sharingReceivers == null)
			return new ArrayList<Client>();
		return sharingReceivers;
	}

	public void setSharingReceivers(List<Client> sharingReceivers) {
		this.sharingReceivers = sharingReceivers;
	}

	@Override
	public int hashCode() {
		return (int) (idSharing ^ idClient.hashCode());
		
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null)
			return false;
		if (obj == this)
			return true;
		if (!(obj instanceof SharingPK))
			return false;
		Sharing s = (Sharing) obj;
		return (s.getIdSharing() == this.idSharing && s.getIdClient().equals(
				this.idClient));
		
	}
	
}
